<template>
	<view>
		<scroll-view scroll-x class="bg-white nav">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="active==0?'text-green cur':''" @tap="tabSelect(0)">
					帮扶记录
				</view>
				<!-- <view class="cu-item flex-sub" :class="active==1?'text-green cur':''" @tap="tabSelect(1)">
					已结束
				</view>
				<view class="cu-item flex-sub" :class="active==2?'text-green cur':''" @tap="tabSelect(2)">
					我的报名
				</view> -->
			</view>
		</scroll-view>
		<view v-if="active == 0" class="ppfl_c">
			<view v-if="noData == false">
				<view v-for="(item,index) in helpRecord" :key="index" class="bg-white margin-top margin-right-xs radius margin-left-xs padding">
					<view class="flex padding-bottom-xs solid-bottom justify-between">
						<view>{{item.govHelpListId}}</view>
					</view>
					<view class="flex margin-top justify-between">
						<view class="text-gray">记录名称</view>
						<view class="text-gray">{{item.listName}}</view>
					</view>
					<view class="flex margin-top-xs justify-between">
						<view class="text-gray">政策名称</view>
						<view class="text-gray">{{item.helpName }}</view>
					</view>
					<view class="flex margin-top-xs justify-between">
						<view class="text-gray">贫困人员</view>
						<view class="text-gray">{{item.poorPersonName}}</view>
					</view>
					<view class="flex margin-top-xs justify-between">
						<view class="text-gray">扶贫干部</view>
						<view class="text-gray">{{item.cadrePersonName }}</view>
					</view>
					<view class="flex margin-top-xs justify-between">
						<view class="text-gray">帮扶开始时间</view>
						<view class="text-gray">{{item.startTime }}</view>
					</view>
					<view class="flex margin-top-xs justify-between">
						<view class="text-gray">帮扶结束时间</view>
						<view class="text-gray">{{item.endTime }}</view>
					</view>
					<view class="flex margin-top-xs justify-between">
						<view class="text-gray">内容</view>
						<view class="text-gray">{{item.listBrief}}</view>
						<jyf-parser :html="context" ref="article"></jyf-parser>
					</view>
				</view>
			</view>
			<view v-else>
				<no-data-page></no-data-page>
			</view>
		</view>
	</view>
</template>

<script>
	
	import noDataPage from '@/components/no-data-page/no-data-page.vue'
	import {queryGovHelpPolicyList} from '../../api/helpInfo/helpInfoApi.js'
	import {queryGovPerson,getUserTel,getUserName} from '../../api/user/userApi.js'
	import jyfParser from "@/components/jyf-parser/jyf-parser";
	import {
		getAreaId
	} from '../../api/area/areaApi.js'
	export default {
		data() {
			return {
				personName:'',
				personLink:'',
				personAge:0,
				personAddress:'',
				remark:'',
				active: 0,
				userId: '',
				caId: '',
				helpRecord: [],
				repaired: [],
				deleteSignup: false,
				signupModal: false,
				curRepair: {},
				noData: false,
				preStaffId: '',
				preStaffName: '',
				context: '',
			}
		},
		components: {
			noDataPage,
			jyfParser
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			let that = this;
			this.vc.onLoad(options);
			that.caId = getAreaId();
			that._loadHelpRecords(that.active);
		},
		onShow: function(){
			if(this.userId && this.caId){
				this._loadHelpRecords(this.active);
			}
		},
		methods: {
		async _loadHelpRecords(_active) {
				let that = this;
				let _poorPersonId = "";
				let dataObj = {
					personName: getUserName(),
					tel: getUserTel(),
					page: 1,
					row: 1
				};
				await queryGovPerson(dataObj).then(_data =>{
					let _json = _data;
					if (_json.code == 0 && _json.data.length > 0) {
							_poorPersonId  = _json.data[0].govPersonId;
					}else{
						uni.showToast({
							icon: 'none',
							title: '未查询到您的信息。'
						});
					}
				})
				let _paramIn = {
					"caId": getAreaId(),
					"poorPersonId": _poorPersonId,
					"page": 1,
					"row": 10
				};
				if(_poorPersonId.length > 0){
					queryGovHelpPolicyList(_paramIn).then(_data =>{
						let _json = _data;
						if (_json.code == 0 && _json.data.length > 0) {
								console.log(_json);
								let _helpRecord = _json.data;
								if (_helpRecord.length < 1) {
									that.noData = true;
								} else {
									that.noData = false;
								}
								that.helpRecord = _helpRecord;
								return;
						}else{
							uni.showToast({
								icon: 'none',
								title: '未查询到您的信息。'
							});
						}
					})
				}
			},
			onChange: function(e) {
				this._loadHelpRecords(e.detail.index);
			},
			tabSelect: function(_active) {
				this.active = _active;
				this._loadHelpRecords(_active);
			},
			_cancleSignUp: function() {
				this.signupModal = false;
			},
			activityDetail: function(_item) {
				console.log(_item);
				this.vc.navigateTo({
					url: '/pages/activityDetail/activityDetail?actId=' + _item.actId
				});
			},
			deleteRepair: function(_repair) {
				this.curRepair = _repair;
				this.deleteSignup = true;
			},
			_cancleDeleteRepair: function() {
				this.deleteSignup = false;
			},
			doSignup: function(_item) {
				this.curRepair = _item;
				this.signupModal = true;
			},
			_doDeleteRepair: function() {
				let that = this;
				deleteGovActivityPerson(this.curRepair)
					.then(_data => {
						uni.showToast({
							icon: 'none',
							title: '删除成功'
						});
						that._cancleDeleteRepair();
						that._loadHelpRecords(2);
					}, err => {
						uni.showToast({
							icon: 'none',
							title: err
						})
					})
			},
			_appraiseRepair: function(_item) {
				
			},
			_doSignup: function() {
				let that = this;
				if (that.personName == '') {
					uni.showToast({
						title: '姓名不能为空',
						icon: 'none'
					});
					return;
				}
				if (that.personLink == '') {
					uni.showToast({
						title: '电话不能为空',
						icon: 'none'
					});
					return;
				}
				if (that.personAge == 0) {
					uni.showToast({
						title: '年龄不能为空',
						icon: 'none'
					});
					return;
				}
				if (that.personAddress == '') {
					uni.showToast({
						title: '住址不能为空',
						icon: 'none'
					});
					return;
				}
				let _data = {
					caId: getAreaId(),
					actId: that.curRepair.actId,
					personName: that.personName,
					personLink: that.personLink,
					personAge: that.personAge,
					personAddress: that.personAddress,
					remark: that.remark
				};
				saveGovActivityPerson(_data)
					.then(_data => {
						uni.showToast({
							icon: 'none',
							title: '报名成功'
						});
						that._cancleSignUp();
					}, err => {
						uni.showToast({
							icon: 'none',
							title: err
						})
					})
			}
		}
	}
</script>

<style>
	.solid-bottom::after {
		border-bottom: 2upx solid rgba(0, 0, 0, 0.1);
	}
</style>
